import vue from '@vitejs/plugin-vue'
import AutoImport from 'unplugin-auto-import/vite'
import Icons from 'unplugin-icons/vite'
import { NaiveUiResolver } from 'unplugin-vue-components/resolvers'
import Components from 'unplugin-vue-components/vite'
import {defineConfig, loadEnv} from 'vite'

const rootPath = new URL('.', import.meta.url).pathname
// https://vitejs.dev/config/
export default defineConfig(({command, mode}) =>{
  const env = loadEnv(mode, process.cwd(),'')
  console.log('env', env.VITE_BASE_API)
  return {
    base: env.VITE_BASE_API,
      plugins: [
        vue(),
        AutoImport({
          imports: [
            {
              'naive-ui': ['useDialog', 'useMessage', 'useNotification', 'useLoadingBar'],
            },
          ],
        }),
        Components({
          resolvers: [NaiveUiResolver()],
        }),
        Icons(),
      ],
      resolve: {
        alias: {
          '@': rootPath + 'src',
          stores: rootPath + 'src/stores',
          wailsjs: rootPath + 'wailsjs',
        },
      },
      server:{
        proxy: {
          ...(mode === 'desktop')? {
            "/api":{
              target: 'http://127.0.0.1:38085',
              rewrite: path => path.replace(/^\/api/,"")
            }
          } : {
            "/api":{
              // target: 'http://10.10.0.1:8080',
              target: 'http://10.10.0.1:38085',
              // target: 'http://127.0.0.1:38085',
              rewrite: path => path.replace(/^\/api/,"")
            }
          }
        }
      }
    }
})
